// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    catelist:["男装","女装","零食","家电","床上用品","家具"],
    banner:[
     {url: "../../images/banner1.jpg"},
     {url: "../../images/banner2.jpg"},
     {url: "../../images/banner3.jpg"}
   
    ],
    longitude:"",
    latitude:"",
    markers:[{
      latitude:28.135653,
      longitude:112.988432,
      name:"网院"
    }]
    },
  //   danmulist:[{
  //     text:"湖南网络工程职业学院",
  //     color:"#ff0000",
  //     time:2
  //   },
  //   {
  //     text:"信息学院",
  //     color:"#ff0000",
  //     time:3
  //   }
  //   ]
  // },
 
  // onReady(e){
  //   this.audioCtx = wx.createAudioContext('myAudio')
  // },
  // data :{
  
  //   audioPlay(){
  //     this.audioPlay()
  //   },
  //   audioPause(){
  //     this.audioCtx.Pause()
  //   },
  //   audio14(){
  //     this.audioCtx.seek(14)
  //   },
  //   audioStart(){
  //     this.audioCtx.seek(0)
  //   }
  // },
 
  onLoad() {
    this.addStorage();
    this.getLocal();
   this.share();
   this.getShareInfo();
  },
  saveImag:function(){
    wx.getImageInfo({
      src: '../../images/banner1.jpg',
      success(res){
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
    })
  }
    })
  },
  selectImg:function(){
    wx.chooseImage({
      count: 1,
      sourceType:['camera'],
      success(res){
        console.log(res)

        wx.previewImage({
          urls: [res.tempFilePaths[0]],
          showmenu:true
        })
        wx.getImageInfo({
          src: res.tempFilePaths[0],
          success(res){
            console.log(res)
          }
        })
      }
    })
  },
  // 存储数据到本地缓存中
  addStorage:function(){
    wx.setStorage({
      data: {"name":"柳星婷","studentid":"201965110422"},
      key: 'userinfo',
    })
    //同步缓存
    wx.setStorageSync('user', {"age":"21","sex":"女"})
  },
  // 获取当前经纬度
  getLocal:function(){
    var then = this;
    wx.getLocation({
      type:'gcj02',
      isHighAccuracy:true,
      success(res){
        console.log(res)
        then.setData({
          latitude:res.latitude,
          longitude:res.longitude
        });
      }
    })
  },
  //打开内置地图
  openLocal:function(res){
    var then = this;
    wx.openLocation({
      latitude: then.data.latitude,
      longitude: then.data.longitude,
      name:"湖南开放大学",
      address:"湖南省长沙市天心区青园路168号实训楼113"
    })
  },
  chooseLocal:function(){
    wx.chooseLocation({
      latitude: then.data.latitude,
      longitude:then.data.longitude,
      success(res){
        console.log(res);
      }
    })
  },
  call:function(){
        wx.makePhoneCall({
          phoneNumber: '15074169629',
        })
  },
    scanCode:function(){
      wx.scanCode({
        onlyFromCamera: true,
        success(res){
          console.log(res)
        }
      })
    },
    share:function(){
      wx.showShareMenu({
        withShareTicket: true,
      menus:['shareAppMessage','shareTimeline']
      })
    },
    onShareAppMessage(){
      return{
        title:"湖南开放大学",
        path:"/pages/car/car",
        imageUrl:"../../images/banner3.jpg"
      }
    },
    onShareTimeline(){
      return{
      title:"今日抢购送一万元大礼包",
      query:"car?id=4",
      imageUrl:"../../images/banner2.jpg"
    }
  },
  getShareInfo:function(){
    wx.getShareInfo({
      shareTicket: 'shareTicket',
     success(res){
       console.log(res)
     }
    })
  }
  })

